package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.CsParkingRateAddNewDTO;
import cn.tedu.eb_film.pojo.dto.CsParkingRateUpdateDTO;
import cn.tedu.eb_film.pojo.entity.CsParkingRate;
import cn.tedu.eb_film.pojo.vo.CsParkingRateListItemVO;
import cn.tedu.eb_film.pojo.vo.CsParkingRateStandardVO;
import cn.tedu.eb_film.service.CsParkingRateService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Slf4j
/**
 * 停车规则表(CsParkingRate)表控制层
 *
 * @author HおE
 * @since 2023-03-17 18:48:53
 */
@RestController
@RequestMapping("/csParkingRate")
@Api(tags = "停车规则管理模块")
public class CsParkingRateController {

    @PostMapping("/{id:[0-9]+}/enable")
    @ApiOperation("启用类别")
    @ApiOperationSupport(order = 220)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "int")
    })
    public JsonResult<Void> setEnable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Integer id) {
        log.debug("开始处理【启用停车规范】的请求，参数：{}", id);
        csParkingRateService.setEnable(id);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/disable")
    @ApiOperation("禁用类别")
    @ApiOperationSupport(order = 221)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "int")
    })
    public JsonResult<Void> setDisable(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Integer id) {
        log.debug("开始处理【禁用停车规范】的请求，参数：{}", id);
        csParkingRateService.setDisable(id);
        return JsonResult.ok();
    }

    /**
     * 服务对象
     */

    @Autowired
    private CsParkingRateService csParkingRateService;

    /**
     * 新增数据
     *
     * @param csParkingRateAddNewDTO 实体
     * @return 新增结果
     */
    @PostMapping("/add-new")
    @ApiOperation("根据ID插入数据")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(CsParkingRateAddNewDTO csParkingRateAddNewDTO) {
        csParkingRateService.insert(csParkingRateAddNewDTO);
        return JsonResult.ok();
    }
    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/{id:[0-9]+}/deleteById")
    @ApiOperation("根据ID删除数据")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable Integer id) {
        csParkingRateService.deleteById(id);
        return JsonResult.ok();
    }

    /**
     * 编辑数据
     *
     * @param csParkingRateUpdateDTO 实体
     * @return 编辑结果
     */
    @PostMapping("/{id:[0-9]+}/updateById")
    @ApiOperation("根据ID修改数据")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> updateById(@PathVariable Integer id,CsParkingRateUpdateDTO csParkingRateUpdateDTO) {
        csParkingRateService.updateById(id,csParkingRateUpdateDTO);
        return JsonResult.ok();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/{id:[0-9]+}/selectById")
    @ApiOperation("查询单个数据")
    @ApiOperationSupport(order = 400)
    public JsonResult<CsParkingRateStandardVO> selectById(@PathVariable Integer id) {
        CsParkingRateStandardVO csParkingRateStandardVO = csParkingRateService.selectById(id);
        return JsonResult.ok(csParkingRateStandardVO);
    }

    /**
     * 查询数据列表
     *
     * @return 数据列表
     */
    @GetMapping("/selectList")
    @ApiOperation("查询数据列表")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<CsParkingRateListItemVO>> selectList() {
        List<CsParkingRateListItemVO> list=csParkingRateService.selectList();

        return JsonResult.ok(list);


    }

}

